<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>工作流测试</title>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          
          <div class="layui-inline">
             <label class="layui-form-label">商品名称</label>
             <div class="layui-input-inline">
               <input type="text" class="layui-input" name="sname" placeholder="请输入" autocomplete="off">
             </div>
           </div>           
          
          	  <div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-ask-bill-search">
	              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              <i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
	          </div>
          
        </div>
        
      </div>
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          	<button class="layui-btn layuiadmin-btn-admin " data-type="add">
          	 <i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新增
          	</button>
        </div>
        <!-- 数据表单  -->
        <div class="layui-tab-item layui-show">
			<div class="layui-card">
	          <div class="layui-card-body">
	            <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
	              <ul class="layui-tab-title">
	                <li class="layui-this"><B>我发起的</B></li>
	                <li><B>我审批的</B></li>
	              </ul>
	              <div class="layui-tab-content">
	                <div class="layui-tab-item layui-show">
	               		<!-- 业务   数据表单 -->
        				<table id="LAY-ask-bill-manage" lay-filter="LAY-ask-bill-manage"></table>
        			</div>
	                <div class="layui-tab-item">
	                	<!-- 审批   数据表单  -->
        				<table id="LAY-ask-bill-manage-mySee" lay-filter="LAY-ask-bill-manage-mySee"></table>
        			</div>
	              </div>
	              </div>
	            </div>
	          </div>
	        </div>
	    </div>    
        
        <!-- 新增询价单 -->
        <div class="layui-form" lay-filter="add_form" id="add_form" style="padding: 20px 30px 0 0;display:none">
        	<form id="save_form">
        	
		    <div class="layui-form-item">
		      <label class="layui-form-label">采购商品名称</label>
		      <div class="layui-input-block">
		        <input type="text" name="sname" maxlength="100" lay-verify="required" placeholder="请输入商品名称" autocomplete="off" class="layui-input">
		      </div>
		    </div>
		    <div class="layui-form-item">
		      <label class="layui-form-label">采购金额（元）</label>
		      <div class="layui-input-block">
		        <input type="text" name="amount"  lay-verify="required|number" placeholder="请输入金额（元）" onblur="arabiaToCN(this);"  autocomplete="off" class="layui-input">
		      	<div class="layui-form-mid" id="allocateAmountCN" style="color: #FF5722">大写金额</div>
		      </div>
		    </div>
		  	
		    <div class="layui-form-item layui-hide">
		      <input type="button" lay-submit lay-filter="add_form_submit" id="add_form_submit" value="保存" />
		    </div>
		    </form>
	  	</div>
    </div>
  </div>

  <script>
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table', 'set', 'laydate', 'upload', 'element'], function(){
    var $ = layui.$
    ,form = layui.form
    ,laydate = layui.laydate
    ,upload = layui.upload
    ,element = layui.element
    ,table = layui.table;
  
    // 表单
    table.render({
      elem: '#LAY-ask-bill-manage'
      ,url: basePath + '/testBiz/queryDataByCondition' //请求数据接口
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'sname', title: '采购商品名称'}
        ,{field: 'amount', title: '采购金额（元）'}
        ,{field: 'processStatus', title: '审批状态',templet: function(d){
	        	var stateStr = '';
	    		if(d.processStatus == '1'){
	    			stateStr = '审批中';
	    		}else if(d.processStatus == '9'){
	    			stateStr = '审批完成';
	    		}else if(d.processStatus == '10'){
	    			stateStr = '<span class="layui-badge layui-bg-cyan">审批终止</span>';
	    		}
	  			return stateStr;
        	}
        }
        ,{title: '操作', width:180, align:'center', fixed: 'right', templet: function(d){
        	var optStr ="";
	      	optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon layui-icon-form"></i>详情</a>';
  		  	return optStr;
        	}
        }
      ]]
      ,page: true
      ,limit: 10
    });
    // 表单-我审批的
    table.render({
        elem: '#LAY-ask-bill-manage-mySee'
        ,url: basePath + '/testBiz/queryDataByConditionMySee' //请求数据接口
        ,cols: [[
          {type: 'checkbox', fixed: 'left'}
          ,{field: 'sname', title: '采购商品名称'}
          ,{field: 'amount', title: '采购金额（元）'}
          ,{field: 'mineStatus', title: '审批状态',templet: function(d){
        	  var stateStr = '';
    		  if(d.mineStatus == '0'){
    			  stateStr = '我已审批';
    		  }else if(d.mineStatus == '1'){
    			  stateStr = '<span class="layui-badge layui-bg-red">待我审批</span>';
    		  }else if(d.mineStatus == '9'){
    			  stateStr = '审批完成';
    		  }else if(d.mineStatus == '10'){
    			  stateStr = '<span class="layui-badge layui-bg-cyan">审批终止</span>';
    		  }
  			  return stateStr;
          	}
          }
          ,{title: '操作', width:180, align:'center', fixed: 'right', templet: function(d){
          	var optStr ="";
  	      	optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail-mySee"><i class="layui-icon layui-icon-form"></i>详情</a>';
    		  	return optStr;
          	}
          }
        ]]
        ,page: true
        ,limit: 10
      });
    
    //监听搜索
    form.on('submit(LAY-ask-bill-search)', function(data){
      //执行重载
      table.reload('LAY-ask-bill-manage', {page: {curr: 1},
        where: trimData(data)
      });
      //执行重载-我审批的
      table.reload('LAY-ask-bill-manage-mySee', {page: {curr: 1},
        where: trimData(data)
      });
    });
    //重置清空
    form.on('submit(LAY-user-back-reset)', function(data){
    	reset_form('query-form');
    });
   
    
    // 监听操作列
    table.on('tool(LAY-ask-bill-manage)', function(obj){
      var data = obj.data;
      if(obj.event === 'detail'){
    	  parent.layui.index.openTabsPage(basePath + '/testBiz/toDealOrDetail?id='+data.id, '表单 > 详情');
      }
    });
    // 监听操作列-我审批的
    table.on('tool(LAY-ask-bill-manage-mySee)', function(obj){
      var data = obj.data;
      if(obj.event === 'detail-mySee'){
    	  parent.layui.index.openTabsPage(basePath + '/testBiz/toDealOrDetail?id='+data.id, '表单 > 详情');
      }
    });
    
    // 按钮事件
    var active = {
      add: function(){
    	  clean_form("add_form");//清空表单
    	  $(".layui-upload-list").html('');//清空照片
    	  $("input[name=excelPath]").remove();
    	  $("input[name=pdfPath]").remove();
    	  layer.open({
       		type: 1
          	,title: '新增'
          	,content: $('#add_form')
          	,area: layui.admin.screen() < 2 ? ['80%', '350px'] : ['520px','350px']
          	,btn: ['确定', '取消']
          	,btnAlign: 'c'
          	,yes: function(index, layero){
          		var submitID = 'add_form_submit'
            	,submit = layero.contents().find('#'+ submitID);
              	//监听提交
           	  	form.on('submit('+ submitID +')', function(data){
	              	//提交 Ajax 成功后，静态更新表格中的数据
	              	var field = data.field; //获取提交的字段
	              	$.ajax({
	                  	type : 'post',
						url : basePath + '/testBiz/save',
	                  	data: field,
						success:function(result){
							if(result.success){
	              				table.reload('LAY-ask-bill-manage'); //数据刷新
	              				clean_form("add_form");//清空表单
	              				layer.close(index); //关闭弹层
							}else{
								layer.msg(result.msg,{icon: 7});
						  	}
						}
	              	});
            	});  
            	submit.trigger('click');
       			}
       		}); 
      	}
    }  
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  	
  });
  	
  
  	//根据url查看文件
	function showImg(url){
		var openWin = window.open(url,'','left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
	}
  	
  	//小写转大写
	function arabiaToCN(obj){
  		if(obj.value == '' || obj.value == null){
  			return;
  		}
  		var cnValue = convertCurrency(obj.value);
  		layui.$(obj).next().html(cnValue);
	}
  </script>
</body>
</html>

